package com.sgb.merchant.view.adapter;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.link.entity.merchant.ApplyEntity;
import com.sgb.merchant.BR;
import com.sgb.merchant.R;

import java.util.List;


public class ApplyListAdapter extends BaseQuickAdapter<ApplyEntity, BaseViewHolder> {

    BtnOnClickListener btnOnClickListener;


    public void setBtnOnClickListener(BtnOnClickListener btnOnClickListener) {
        this.btnOnClickListener = btnOnClickListener;
    }

    public ApplyListAdapter(@Nullable @org.jetbrains.annotations.Nullable List<ApplyEntity> data) {
        super(R.layout.merchant_item_self_apply,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ApplyEntity item) {
        ViewDataBinding binding = DataBindingUtil.bind(helper.itemView);
        binding.setVariable(BR.viewModel, item);
        if(!TextUtils.isEmpty(item.getStatus())) {//0 上架 1下架
            switch (item.getStatus()) {
                case "0":
                    helper.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_putaway_green);
                    helper.setVisible(R.id.tv_project_detail,true);
                    break;
                case "1":
                    helper.setImageResource(R.id.iv_state, R.mipmap.merchant_icon_downaway);
                    helper.setVisible(R.id.tv_project_detail,false);
                    break;
            }
        }
        helper.setOnClickListener(R.id.tv_project_detail, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(btnOnClickListener!=null){
                    btnOnClickListener.projectDetail(item);
                }

            }
        }).setOnClickListener(R.id.tv_detail, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(btnOnClickListener!=null){
                    btnOnClickListener.applyDetail(item);
                }

            }
        });
    }

    public interface  BtnOnClickListener{

        void projectDetail(ApplyEntity entity);

        void applyDetail(ApplyEntity entity);
    }
}
